package com.sky.module.system.userloginrecord.service.impl;

import com.sky.module.system.apistatistics.service.ApiStatisticesService;
import com.sky.module.system.user.domain.entity.User;
import com.sky.module.system.userloginrecord.domain.po.UserLoginRecordPo;
import com.sky.module.system.userloginrecord.mapper.UserLoginRecordMapper;
import com.sky.module.system.userloginrecord.service.UserLoginRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author
 * @date 2023/3/12 9:07
 **/
@Service
public class UserLoginRecordServiceImpl implements UserLoginRecordService {

    @Autowired
    private UserLoginRecordMapper userLoginRecordMapper;

    @Autowired
    private ApiStatisticesService apiStatisticesService;

    @Override
    public Map<String, Long> getUserLoginCount(Long userId) {


        UserLoginRecordPo userLoginRecordPo = userLoginRecordMapper.getUserLoginCount(userId);
        Long apiStatistices = apiStatisticesService.getApiStatisticesWeekCount(userId);
        // 获取当前用户总登录次数
        Long loginTotalCount = userLoginRecordMapper.getUserTotalCount(userId);

        Long apiStatisticesTotalCount = apiStatisticesService.getApiStatisticesTotalCount(userId);
        Map<String, Long> map = new HashMap<>();
        // 每周的登录次数
        map.put("weekLoginCount", userLoginRecordPo.getLoginWeekCount());
        // 获取每周的api访问次数
        map.put("apiStatistices", apiStatistices);
        map.put("apiStatisticesTotalCount", apiStatisticesTotalCount);
//            userLoginRecordPo
        // 总的登录次数
        map.put("loginTotalCount", loginTotalCount);
        return map;


    }
}
